/**
 * 
 */
package evance.server.common.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.mysema.query.BooleanBuilder;
import com.mysema.query.jpa.JPQLQuery;
import com.mysema.query.jpa.impl.JPAQuery;
import com.trg.dao.jpa.GenericDAOImpl;

import evance.data.model.entity.EvRole;
import evance.data.model.entity.QEvCustomer;
import evance.data.model.entity.QEvCustomerRole;
import evance.data.model.entity.QEvRole;
import evance.server.common.constants.UnitName;

/**
 * @author BaoVuong
 *
 */
@Repository
public class RoleDAOImpl extends GenericDAOImpl<EvRole, Long> implements RoleDAO {

	@PersistenceContext(unitName = UnitName.EVANCE)
	@Override
	public void setEntityManager(EntityManager entityManager) {
		super.setEntityManager(entityManager);
	}

	@Override
	public List<EvRole> getListRoles(Long customerId) {
		JPQLQuery query = new JPAQuery(em());
		QEvCustomer qEvCustomer = QEvCustomer.evCustomer;
		QEvCustomerRole qCustomerRole = QEvCustomerRole.evCustomerRole;
		QEvRole qEvRole = QEvRole.evRole;

		BooleanBuilder builder = new BooleanBuilder();
		builder.and(qEvCustomer.id.eq(customerId));

		List<EvRole> result = query.from(qCustomerRole).join(qCustomerRole.evCustomer, qEvCustomer).join(qCustomerRole.evRole, qEvRole).list(qEvRole);
		return result;
	}

	@Override
	public List<EvRole> getListRoles(String username) {
		// TODO Auto-generated method stub
		return null;
	}

}
